<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

/**
 * @mixin \think\Model
 */
class Shop extends Model
{
    public static function getShop($id){
        $shop = self::where(['shop_id'=>$id])->find();
        if(!$shop) return[];
        $shop = $shop->toArray();
        $shop['categorys'] = [];
        $newArr = [];
        if($shop['cate_attr']){
            $shop['cate_attr'] = json_decode($shop['cate_attr'], true);
            $cate_first = [];
            foreach($shop['cate_attr'] as $k=>$v){
                $cate_first[] = $v['big'];
            }
            $cate_first = array_unique($cate_first);
            foreach($shop['cate_attr'] as $k=>$v){
                foreach($cate_first as $j=>$v2){
                    if($v2 == $v['big']){
                        $newArr[$j]['name'][] = $v2;
                        $newArr[$j]['name'] = array_unique($newArr[$j]['name']);
                        $newArr[$j]['sub'][] = $v['first'];
                    }
                }
            }
            $shop['categorys'] = $newArr;
        }
        return $shop;
    }
}
